import {observable, action, toJS} from 'mobx';
import * as RepeatAPI from '../apis/repeat';
import {WeaLocaleProvider} from 'ecCom';
import {message} from 'antd';
import {WeaTableNew, WeaForm} from 'comsMobx';
const {TableStore} = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;

export default class Repeat {
  @observable title = `${getLabel(33277,'周期会议')}`;
  @observable loading = false;
  @observable timeSag = 0;
  @observable conditioninfo = [];
  @observable searchParamsAd = {};
  @observable fields = {};
  @observable meetingid = "";

  //高级搜索
  @observable showSearchAd = false;
  @observable comsWeaTableStore = new TableStore();

  // @observable enddate = "";
  @observable topTab = [];
  
  @observable advanceModalparams = '';
  @observable controlModal = false;
  createDate = new Date();
  @observable previewMeetingId = '';
  @observable createMeetType = 'create';
  // @observable roomPlanVisible = false;
  @observable dialogZIndex = 801;
  @observable userList = [];

  @observable enddate = ''; //提前结束重复会议 -- datePicker限定值
  @observable repeatenddate = ''; //提前结束重复会议 -- datePicker值
  @observable repeatbegindate = ''; //提前结束重复会议 -- datePicker限定值
  
  //table
  @observable dataKey = '';
  // @observable comsWeaTableStore = {};
  //form
  @observable form = new WeaForm();
  
  @observable selectRowKeys = [];

  @action
    
  doInit = () => {
    this.showSearchAd = false;
    this.comsWeaTableStore = new TableStore();
    this.getRepeatDatas();
    this.getCondition();
  }

  setState = (params = {}) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    });
    return this;
  }

  addUser(params) {
    this.userList.push({name: "dyf"});
  }

  getUserList(params) {
    return this.userList.slice();
  }

  //加载列表
  getRepeatDatas = (showFirstPage = true) => {
    const params = this.form && this.form.getFormParams();
    RepeatAPI.getRepeatDatas(params).then((data) => {
      showFirstPage ? this.comsWeaTableStore.getDatas(data.sessionkey,  1) : this.comsWeaTableStore.getDatas(data.sessionkey);
    })
  }


  //初始化会议查询页查询条件
  getCondition = params => {
    RepeatAPI.getCondition(params).then(data => {
      this.form.initFormFields(data.conditioninfo);
      this.conditioninfo = data.conditioninfo;
      this.topTab = data.groupinfo;
    })
  }

  //高级搜索表单内容
  saveFields = (value = {}) => {
    this.fields = value;
    this.searchParamsAd = function () {
      let params = {};
      if (value) {
        for (let key in value) {
          params[value[key].name] = value[key].value
        }
      }
      return params
    }();
  }

  //立即终止周期会议, 提前结束周期会议
  StopIntvl = (params) => {
    RepeatAPI.StopIntvl(params).then(result => {
      if(result.status){
        message.success(`${getLabel(30700,'操作成功')}`);
        this.getRepeatDatas(false)
      }else {
        message.error(`${getLabel(384137,'操作失败！')}`);
      }
    })
  }

  //取消周期会议
  CancelIntvl = (meetingid, searchParamsAd) => {
    RepeatAPI.CancelIntvl(meetingid).then(result => {
      if(result.status){
        message.success(`${getLabel(30700,'操作成功')}`);
        this.getRepeatDatas(false)
      }else {
        message.error(`${getLabel(384137,'操作失败！')}`);
      }
    })
  }
  
  //删除周期会议
  DeleteIntvl = params => {
    RepeatAPI.DeleteIntvl(params).then(result => {
      if(result.status){
        message.success(`${getLabel(30700,'操作成功')}`);
        this.getRepeatDatas(false)
      }else {
        message.error(`${getLabel(384137,'操作失败！')}`);
      }
    })
  }

  savePreviewMeetingId = (value = {}) => {
    this.previewMeetingId = value.meetingid;
  }

  setZIndex = (value = '') => {
    this.dialogZIndex = value;
  }
  
  getFormParams() {
    return this.form.getFormParams();
  }
}
